<template>
    <div>
        <h1>Dialog对话框的基本使用</h1>
        <el-button @click="dialogTableVisible = true">打开嵌套表格的 Dialog</el-button>
        <!--
           title="收货地址"    弹出层的标题
           :visible.sync="dialogTableVisible"     控制显示和隐藏的属性  true  显示  false 隐藏
        -->
        <el-dialog title="收货地址" :visible.sync="dialogTableVisible">
            <el-table :data="tableData">
                <el-table-column property="date" label="日期" width="150"></el-table-column>
                <el-table-column property="name" label="姓名" width="200"></el-table-column>
                <el-table-column property="address" label="地址"></el-table-column>
            </el-table>
        </el-dialog>

        <hr>
        <!-- Form -->
        <el-button @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button>

        <el-dialog title="收货地址" :visible.sync="dialogFormVisible" @close="clearForm">
            <el-form :model="form">
                <el-form-item label="活动名称" :label-width="formLabelWidth">
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="活动区域" :label-width="formLabelWidth">
                    <el-select v-model="form.region" placeholder="请选择活动区域">
                        <el-option label="区域一" value="shanghai"></el-option>
                        <el-option label="区域二" value="beijing"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>

            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="login">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "DialogView",
    data() {
        return {
            dialogFormVisible: false,
            dialogTableVisible: false, //  控制弹出层的显示和隐藏  true  显示  false  隐藏
            tableData: [
                {
                    date: '2016-05-02',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄'
                }, {
                    date: '2016-05-04',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄'
                }, {
                    date: '2016-05-01',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄'
                }, {
                    date: '2016-05-03',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄'
                }
            ],
            formLabelWidth: '120px',
            form: {
                name: '',
                region: ''
            }
        }
    },
    methods: {
        login() {
            // this.$message.success("登录请求已发送"+JSON.stringify(this.form))

            this.$message({
                message: "登录请求已发送" + JSON.stringify(this.form),
                type: "success",
                onClose: () => {
                    this.dialogFormVisible = false
                    // this.form = {}
                }
            })

            //  发送异步请求    code   0   110  500

        },
        clearForm() {  //  弹窗关闭时 回调
            this.$message("弹窗关闭了")
            this.form = {}
        }
    }
}
</script>

<style scoped>

</style>